<script>
  var fillCups = function (amount) {
    let ans = 0;
    amount.sort((a, b) => b - a);
    while (amount[0] > 0) {
      amount[0]--;
      ans++;
      if (amount[1]>0) {
        amount[1]--;
      }
      amount.sort((a, b) => b - a);
    }
    return ans;
  };
  console.log(fillCups([1, 4, 2]));
</script>